package com.suanfa.sort2;

import com.suanfa.node.ListNode;

/**
 * @author jukg
 * @date 2025/04/08 11:30
 * @description
 */
public class BubboSort {

    public static void bubbo(String[] args) {
        int[] arr =new int[]{1,44,2,3,5,6,1,5555};

        for(int i =0; i< arr.length; i++){
            for(int j = i+1; j< arr.length; j++){
                if(arr[i]> arr[j]){
                    int temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }

        }
        System.out.println(arr);
    }

    public static void quickSort(int[] arr, int start, int end) {
        int p = arr[start];
        int low = start;
        int high = end;

        while(low < high){

            while(end > low && arr[end]> p){
                end --;
            }
            arr[low] = arr[high];
            while(low < end && arr[low]< p){
                low ++;
            }
            arr[high] = arr[low];

        }

        arr[low] = p;
        quickSort(arr, start, low);
        quickSort(arr, low+1, end);
    }

    int binarySearch(int arr[], int target){

        int l = 0, r = arr.length-1;

        while(l <= r){
            int mid = (l+r)/2;
            if(arr[mid] == target){
                return mid;
            }else if(arr[mid] < target){
                l = mid+1;
            }else {
                r = mid-1;
            }
        }
        return -1;

    }

    void revweseNode(ListNode node){

        ListNode pre = null;
        ListNode cur = node;
        ListNode next = null;

        while(cur != null){
            next = node.next;
            cur.next = pre;
            pre = cur;
            cur = next;
        }

    }
}

